package pri.zxx.word;

import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.TextAlignment;
import org.junit.jupiter.api.Test;
import pri.zxx.word.dat.ExperimentResult;
import pri.zxx.word.dat.FontSizeType;
import pri.zxx.word.dat.TableType;
import pri.zxx.word.dat.WordData;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Slf4j
public class PoiWordTest {

    @Test
    public void test2() {
        WordData wordData = new WordData();

        List<ExperimentResult> resultList = new ArrayList<>();

        resultList.add(new ExperimentResult().setExpId(1L)
                .setExpTypeName("蛋白质")
                .setGroupName("T1")
                .setIndicator("指标1")
                .setValue(BigDecimal.valueOf(10))
                .setVariance(new BigDecimal("1.133"))
                .setSubscript("b"));
        resultList.add(new ExperimentResult().setExpId(1L)
                .setExpTypeName("蛋白质")
                .setGroupName("T2")
                .setIndicator("指标1")
                .setValue(BigDecimal.valueOf(20))
                .setVariance(new BigDecimal("2.133"))
                .setSubscript("a"));
        resultList.add(new ExperimentResult().setExpId(1L)
                .setExpTypeName("蛋白质")
                .setGroupName("T3")
                .setIndicator("指标1")
                .setValue(BigDecimal.valueOf(30))
                .setVariance(new BigDecimal("3.133"))
                .setSubscript("c"));
        resultList.add(new ExperimentResult().setExpId(1L)
                .setExpTypeName("蛋白质")
                .setGroupName("T4")
                .setIndicator("指标1")
                .setValue(BigDecimal.valueOf(40))
                .setVariance(new BigDecimal("4.133"))
                .setSubscript("d"));
        wordData.setExperimentResults(resultList);

        List<WordData.GroupInfo> groupInfos = new ArrayList<>();
        groupInfos.add(new WordData.GroupInfo().setGroupName("T1").setDesc("分组1").setOrder(1).setGroupId(1L));
        groupInfos.add(new WordData.GroupInfo().setGroupName("T2").setDesc("分组2").setOrder(2).setGroupId(2L));
        groupInfos.add(new WordData.GroupInfo().setGroupName("T3").setDesc("分组3").setOrder(3).setGroupId(3L));
        groupInfos.add(new WordData.GroupInfo().setGroupName("T4").setDesc("分组4").setOrder(4).setGroupId(4L));
        groupInfos.add(new WordData.GroupInfo().setGroupName("T5").setDesc("分组5").setOrder(5).setGroupId(5L));
        groupInfos.add(new WordData.GroupInfo().setGroupName("T6").setDesc("分组6").setOrder(6).setGroupId(6L));
        wordData.setGroupInfos(groupInfos);

        List<WordData.StageInfo> stageInfoList = new ArrayList<>();


        List<WordData.SimpleTableInfo> rawInfo = new ArrayList<>();
        rawInfo.add(new WordData.SimpleTableInfo().setName("原料1").setValue(BigDecimal.valueOf(100))
                .setStageId(1L).setGroupId(1L));
        rawInfo.add(new WordData.SimpleTableInfo().setName("原料1").setValue(BigDecimal.valueOf(99))
                .setStageId(1L).setGroupId(2L));
        rawInfo.add(new WordData.SimpleTableInfo().setName("原料2").setValue(BigDecimal.valueOf(19))
                .setStageId(1L).setGroupId(1L));
        rawInfo.add(new WordData.SimpleTableInfo().setName("原料2").setValue(BigDecimal.valueOf(18))
                .setStageId(1L).setGroupId(3L));


        List<WordData.SimpleTableInfo> nutritionInfo = new ArrayList<>();
        nutritionInfo.add(new WordData.SimpleTableInfo().setGroupId(1l).setStageId(1L).setName("营养指标1")
                .setValue(BigDecimal.valueOf(11)));
        nutritionInfo.add(new WordData.SimpleTableInfo().setGroupId(2l).setStageId(1L).setName("营养指标1")
                .setValue(BigDecimal.valueOf(2)));
        stageInfoList.add(new WordData.StageInfo().setStageName("0-1").setDesc("阶段1")
                .setStartDays(1).setEndDays(10).setRawInfos(rawInfo).setNutritionInfo(nutritionInfo));
        wordData.setStageInfoList(stageInfoList);

        WordBaseDataProperties wordBaseDataProperties = new WordBaseDataProperties();
        List<WordBaseDataProperties.SentenceInfo> list = new ArrayList<>();
        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(24.0).setStLineSpacingRule(2)
                .setLineBefore(12.0).setLineAfter(12.0)
                .setParagraphAlignment(ParagraphAlignment.BOTH).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("试验编号：{experimentNo}").setBold(true).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(18))));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(24.0).setStLineSpacingRule(2)
                .setLineBefore(12.0).setLineAfter(12.0)
                .setParagraphAlignment(ParagraphAlignment.BOTH).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("试验名称：{experimentName}").setBold(true).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(18)
                        .setReturnCount(1))));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.CENTER).setTextAlignment(TextAlignment.AUTO)
                .setLineBefore(12.0).setLineAfter(12.0)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("独创性说明")
                        .setBold(true).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(18).setReturnCount(1))));


        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.BOTH).setTextAlignment(TextAlignment.AUTO)
                .setOverFlowPunct(false).setIndentChart(2)
                .setLineBefore(12.0).setLineAfter(12.0)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("本人郑重声明：所呈交的研发报告是我个人在饲料研究院领导及同事的支持和帮助下开展的研究工作及其取得的研究成果。此项报告中不包含其它人已经公开或撰写过的研究成果。")
                        .setBold(false).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12))));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.RIGHT).setTextAlignment(TextAlignment.AUTO)
                .setOverFlowPunct(false)
                .setLineBefore(12.0).setLineAfter(12.0)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("报告撰写者：{experimentUserName}")
                        .setBold(false).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12).setReturnCount(1))));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.CENTER).setTextAlignment(TextAlignment.AUTO)
                .setOverFlowPunct(false)
                .setLineBefore(12.0).setLineAfter(12.0)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("研发报告产权声明书")
                        .setBold(true).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(18).
                        setReturnCount(1))));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.BOTH).setTextAlignment(TextAlignment.AUTO)
                .setOverFlowPunct(false)
                .setLineBefore(12.0).setLineAfter(12.0).setIndentChart(2)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("本研发报告的所有权属于新希望六和股份有限公司。未经新希望六和股份有限公司饲料研究院院长允许，本报告不得被查阅和借阅。新希望六和股份有限公司饲料研究院院长有权决定向相关单位或人员送交本报告的复印件和电子版。")
                        .setBold(false).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12))));


        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.RIGHT).setTextAlignment(TextAlignment.AUTO)
                .setLineBefore(12.0).setLineAfter(12.0)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("报告撰写者：xx")
                        .setBold(false).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12))));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.RIGHT).setTextAlignment(TextAlignment.AUTO)
                .setLineBefore(12.0).setLineAfter(12.0)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("报告审核者：xx")
                        .setBold(false).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12))));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.RIGHT).setTextAlignment(TextAlignment.AUTO)
                .setLineBefore(12.0).setLineAfter(12.0)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("新希望饲料研究院院长：周桂莲")
                        .setBold(false).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12))));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.RIGHT).setTextAlignment(TextAlignment.AUTO)
                .setLineBefore(12.0).setLineAfter(12.0)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("日期：{experimentTime}")
                        .setBold(false).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12))));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.CENTER).setTextAlignment(TextAlignment.AUTO).setPageBreak(true)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("{experimentName}")
                        .setBold(true).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(14))));

        List<WordBaseDataProperties.RunInfo> runInfos = new ArrayList<>();
        WordBaseDataProperties.RunInfo r1 = new WordBaseDataProperties.RunInfo().setText("摘  要：")
                .setBold(true).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12);
        WordBaseDataProperties.RunInfo r2 = new WordBaseDataProperties.RunInfo().setText("{experimentTarget}。试验选取{animalType}{animalCount} {unit}，分为{groupCount}个处理，每个处理{repeatTimes}个重复，每个重复{[动物需求数量/重复数量]} {unit}。①生长性能结果表明，xxxx。②蛋品质结果表明，xxxx。③屠宰性能结果表明，xxxx。④肉品质结果表明，xxxx。⑤血清生化结果表明，xxxx。⑥免疫结果表明，xxxx。⑦抗氧化结果表明，xxxx。试验总体结论：xxx。")
                .setBold(false).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12);
        runInfos.add(r1);
        runInfos.add(r2);
        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.BOTH).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(runInfos));

        List<WordBaseDataProperties.RunInfo> keyWords = new ArrayList<>();
        WordBaseDataProperties.RunInfo k1 = new WordBaseDataProperties.RunInfo().setText("关键词：")
                .setBold(true).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12);
        WordBaseDataProperties.RunInfo k2 = new WordBaseDataProperties.RunInfo().setText("{keywords}")
                .setBold(false).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12);
        keyWords.add(k1);
        keyWords.add(k2);
        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.BOTH).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(keyWords));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.LEFT).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("1. 前  言")
                        .setBold(true).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12))));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1).setIndentChart(2)
                .setParagraphAlignment(ParagraphAlignment.BOTH).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("请补充研究背景、目的与意义。").setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12)
                        .setBold(false))));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.LEFT).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("2. 材料与方法")
                        .setBold(true).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12))));
        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.LEFT).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("2.1 试验材料")
                        .setBold(true).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12))));
        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1).setIndentChart(2)
                .setParagraphAlignment(ParagraphAlignment.BOTH).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("请补充材料说明。").setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12)
                        .setBold(false))));
        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.LEFT).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("2.2 试验设计与动物")
                        .setBold(true).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12))));
        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1).setIndentChart(2)
                .setParagraphAlignment(ParagraphAlignment.BOTH).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("选取{animalType}{animalCount} {unit}，分为{groupCount}个处理。每个处理{repeatTimes}个重复，每个重复{[动物需求数量/重复数量]} {unit}。试验分为{groupCount}个阶段，试验期总共{sum(阶段天数)}天。").setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12)
                        .setBold(false))).setTableType(TableType.GROUP_DATA));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1)
                .setParagraphAlignment(ParagraphAlignment.LEFT).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("2.3 试验日粮")
                        .setBold(true).setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12))));

        list.add(new WordBaseDataProperties.SentenceInfo()
                .setLineSpace(1.5).setStLineSpacingRule(1).setIndentChart(2)
                .setParagraphAlignment(ParagraphAlignment.BOTH).setTextAlignment(TextAlignment.AUTO)
                .setRunInfos(Collections.singletonList(new WordBaseDataProperties.RunInfo().setText("配方组成见下表。").setFontSizeType(FontSizeType.ZN_SIZE).setFontSize(12)
                        .setBold(false))).setTableType(TableType.INPUT_DATA));

        wordBaseDataProperties.setSentenceInfoList(list);
        wordData.setWordBaseDataProperties(wordBaseDataProperties);
        new TestReporter().customStyle(wordData).headerFooter(wordData).buildContext(wordData).out("test.docx");
    }
}
